home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsIStyleRuleProcessor.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  9KB  |  217 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37. #ifndef nsIStyleRuleProcessor_h___
  38. #define nsIStyleRuleProcessor_h___
  39.  
  40. #include <stdio.h>
  41.  
  42. #include "nsISupports.h"
  43. #include "nsPresContext.h" // for nsCompatability
  44. #include "nsILinkHandler.h"
  45. #include "nsString.h"
  46. #include "nsChangeHint.h"
  47.  
  48. class nsIStyleSheet;
  49. class nsPresContext;
  50. class nsIContent;
  51. class nsIStyledContent;
  52. class nsISupportsArray;
  53. class nsIAtom;
  54. class nsICSSPseudoComparator;
  55. class nsRuleWalker;
  56.  
  57. // The implementation of the constructor and destructor are currently in
  58. // nsCSSStyleSheet.cpp.
  59.  
  60. struct RuleProcessorData {
  61.   RuleProcessorData(nsPresContext* aPresContext,
  62.                     nsIContent* aContent, 
  63.                     nsRuleWalker* aRuleWalker,
  64.                     nsCompatibility* aCompat = nsnull);
  65.   
  66.   // NOTE: not |virtual|
  67.   ~RuleProcessorData();
  68.  
  69.   void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
  70.     return aContext->AllocateFromShell(sz);
  71.   }
  72.   void Destroy(nsPresContext* aContext) {
  73.     this->~RuleProcessorData();
  74.     aContext->FreeToShell(sizeof(RuleProcessorData), this);
  75.   };
  76.  
  77.   const nsString* GetLang();
  78.  
  79.   nsPresContext*   mPresContext;
  80.   nsIContent*       mContent;       // weak ref
  81.   nsIContent*       mParentContent; // if content, content->GetParent(); weak ref
  82.   nsRuleWalker*     mRuleWalker; // Used to add rules to our results.
  83.   nsIContent*       mScopedRoot;    // Root of scoped stylesheet (set and unset by the supplier of the scoped stylesheet
  84.   
  85.   nsIAtom*          mContentTag;    // if content, then content->GetTag()
  86.   nsIAtom*          mContentID;     // if styled content, then weak reference to styledcontent->GetID()
  87.   nsIStyledContent* mStyledContent; // if content, content->QI(nsIStyledContent)
  88.   PRPackedBool      mIsHTMLContent; // if content, then does QI on HTMLContent, true or false
  89.   PRPackedBool      mIsHTMLLink;    // if content, calls nsStyleUtil::IsHTMLLink
  90.   PRPackedBool      mIsSimpleXLink; // if content, calls nsStyleUtil::IsSimpleXLink
  91.   nsCompatibility   mCompatMode;    // Possibly remove use of this in SelectorMatches?
  92.   PRPackedBool      mHasAttributes; // if content, content->GetAttrCount() > 0
  93.   nsLinkState       mLinkState;     // if a link, this is the state, otherwise unknown
  94.   PRInt32           mEventState;    // if content, eventStateMgr->GetContentState()
  95.   PRInt32           mNameSpaceID;   // if content, content->GetNameSapce()
  96.   RuleProcessorData* mPreviousSiblingData;
  97.   RuleProcessorData* mParentData;
  98.  
  99. protected:
  100.   nsAutoString *mLanguage; // NULL means we haven't found out the language yet
  101. };
  102.  
  103. struct ElementRuleProcessorData : public RuleProcessorData {
  104.   ElementRuleProcessorData(nsPresContext* aPresContext,
  105.                            nsIContent* aContent, 
  106.                            nsRuleWalker* aRuleWalker)
  107.   : RuleProcessorData(aPresContext,aContent,aRuleWalker)
  108.   {
  109.     NS_PRECONDITION(aContent, "null pointer");
  110.     NS_PRECONDITION(aRuleWalker, "null pointer");
  111.   }
  112. };
  113.  
  114. struct PseudoRuleProcessorData : public RuleProcessorData {
  115.   PseudoRuleProcessorData(nsPresContext* aPresContext,
  116.                           nsIContent* aParentContent,
  117.                           nsIAtom* aPseudoTag,
  118.                           nsICSSPseudoComparator* aComparator,
  119.                           nsRuleWalker* aRuleWalker)
  120.   : RuleProcessorData(aPresContext, aParentContent, aRuleWalker)
  121.   {
  122.     NS_PRECONDITION(aPseudoTag, "null pointer");
  123.     NS_PRECONDITION(aRuleWalker, "null pointer");
  124.     mPseudoTag = aPseudoTag;
  125.     mComparator = aComparator;
  126.   }
  127.  
  128.   nsIAtom*                 mPseudoTag;
  129.   nsICSSPseudoComparator*  mComparator;
  130. };
  131.  
  132. struct StateRuleProcessorData : public RuleProcessorData {
  133.   StateRuleProcessorData(nsPresContext* aPresContext,
  134.                          nsIContent* aContent,
  135.                          PRInt32 aStateMask)
  136.     : RuleProcessorData(aPresContext, aContent, nsnull),
  137.       mStateMask(aStateMask)
  138.   {
  139.     NS_PRECONDITION(aContent, "null pointer");
  140.   }
  141.   const PRInt32 mStateMask; // |HasStateDependentStyle| for which state(s)?
  142.                             //  Constants defined in nsIEventStateManager.h .
  143. };
  144.  
  145. struct AttributeRuleProcessorData : public RuleProcessorData {
  146.   AttributeRuleProcessorData(nsPresContext* aPresContext,
  147.                          nsIContent* aContent,
  148.                          nsIAtom* aAttribute,
  149.                          PRInt32 aModType)
  150.     : RuleProcessorData(aPresContext, aContent, nsnull),
  151.       mAttribute(aAttribute),
  152.       mModType(aModType)
  153.   {
  154.     NS_PRECONDITION(aContent, "null pointer");
  155.   }
  156.   nsIAtom* mAttribute; // |HasAttributeDependentStyle| for which attribute?
  157.   PRInt32 mModType;    // The type of modification (see nsIDOMMutationEvent).
  158. };
  159.  
  160.  
  161. // IID for the nsIStyleRuleProcessor interface {015575fe-7b6c-11d3-ba05-001083023c2b}
  162. #define NS_ISTYLE_RULE_PROCESSOR_IID     \
  163. {0x015575fe, 0x7b6c, 0x11d3, {0xba, 0x05, 0x00, 0x10, 0x83, 0x02, 0x3c, 0x2b}}
  164.  
  165. /* The style rule processor interface is a mechanism to separate the matching
  166.  * of style rules from style sheet instances.
  167.  * Simple style sheets can and will act as their own processor. 
  168.  * Sheets where rule ordering interlaces between multiple sheets, will need to 
  169.  * share a single rule processor between them (CSS sheets do this for cascading order)
  170.  *
  171.  * @see nsIStyleRule (for significantly more detailed comments)
  172.  */
  173. class nsIStyleRuleProcessor : public nsISupports {
  174. public:
  175.   NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_PROCESSOR_IID)
  176.  
  177.   // Shorthand for:
  178.   //  nsCOMArray<nsIStyleRuleProcessor>::nsCOMArrayEnumFunc
  179.   typedef PRBool (* PR_CALLBACK EnumFunc)(nsIStyleRuleProcessor*, void*);
  180.  
  181.   /**
  182.    * Find the |nsIStyleRule|s matching the given content node and
  183.    * position the given |nsRuleWalker| at the |nsRuleNode| in the rule
  184.    * tree representing that ordered list of rules (with higher
  185.    * precedence being farther from the root of the lexicographic tree).
  186.    */
  187.   NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData) = 0;
  188.  
  189.   /**
  190.    * Just like the previous |RulesMatching|, except for a given content
  191.    * node <em>and pseudo-element</em>.
  192.    */
  193.   NS_IMETHOD RulesMatching(PseudoRuleProcessorData* aData) = 0;
  194.  
  195.   /**
  196.    * Return how (as described by nsReStyleHint) style can depend on a
  197.    * change of the given content state on the given content node.  This
  198.    * test is used for optimization only, and may err on the side of
  199.    * reporting more dependencies than really exist.
  200.    *
  201.    * Event states are defined in nsIEventStateManager.h.
  202.    */
  203.   NS_IMETHOD HasStateDependentStyle(StateRuleProcessorData* aData,
  204.                                     nsReStyleHint* aResult) = 0;
  205.  
  206.   /**
  207.    * Return how (as described by nsReStyleHint) style can depend on the
  208.    * presence or value of the given attribute for the given content
  209.    * node.  This test is used for optimization only, and may err on the
  210.    * side of reporting more dependencies than really exist.
  211.    */
  212.   NS_IMETHOD HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
  213.                                         nsReStyleHint* aResult) = 0;
  214. };
  215.  
  216. #endif /* nsIStyleRuleProcessor_h___ */
  217.